<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" xmlns:oso="http://osoftware.com/facelets" template="/WEB-INF/templates/mainLayout.xhtml">

	<ui:define name="title">
		<h:outputText value="#{resourceBundle['schedule.title']}" />
		<ui:param name="helpId" value="menu.attentionTime.schedule" />
	</ui:define>

	<ui:define name="pageContent">
		<h:form id="form">
			<p:focus context="form"/>
			<p:fieldset legend="#{resourceBundle['panel.search']}" toggleable="true" collapsed="false">
				<p:panelGrid columns="3">
					<oso:selectOneMenu id="specialist" label="#{resourceBundle['schedule.specialist']}" value="#{attentionTimeModel.filter.specialist}" converter="specialistConverter"
						items="#{attentionTimeModel.selectableSpecialists}" itemLabel="fullName">
					</oso:selectOneMenu>
				</p:panelGrid>
				<p:commandButton value="#{resourceBundle['btn.search']}" action="search" update="schedule" />
			</p:fieldset>
			<p:schedule allDaySlot="false" view="agendaWeek" resizable="false" draggable="false" locale="es"
				slotMinutes="#{attentionTimeModel.filter.specialist != null?attentionTimeModel.filter.specialist.attentionTimeDuration:30}" id="schedule" value="#{attentionTimeController.eventModel}"
				widgetVar="myschedule" minTime="6">

				<p:ajax event="dateSelect" listener="#{attentionTimeController.onDateSelect}" oncomplete="eventDialog.show()" update="attentionTimeDialog" />
				<p:ajax event="eventSelect" listener="#{attentionTimeController.onEventSelect}" oncomplete="eventDialog.show()" update="attentionTimeDialog" />
			</p:schedule>

			<p:dialog widgetVar="eventDialog" header="Detalles del Turno" showEffect="clip" hideEffect="clip" id="attentionTimeDialog">
				<h:panelGrid columns="2" rendered="#{not empty attentionTimeModel.editedEntity.id}">
					<h:outputLabel value="Paciente: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.patient.fullName}" />
					<h:outputLabel value="Fecha: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.date}">
						<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="GMT-3" />
					</h:outputText>
					<h:outputLabel value="Especialista: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.specialistFee.specialist.fullName}" />
					<h:outputLabel value="Estado: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.attentionTimeStatus.name}" />
				</h:panelGrid>
				<p:commandButton value="#{resourceBundle['btn.new']}" action="new" />
				<p:commandButton value="#{resourceBundle['btn.edit']}" action="edit" rendered="#{not empty attentionTimeModel.editedEntity.id}" />
				<p:commandButton value="#{resourceBundle['btn.delete']}" action="delete" oncomplete="handleAttentionTimeServerResponse(xhr, status, args)"
					rendered="#{not empty attentionTimeModel.editedEntity.id}" />
				<p:commandButton value="#{resourceBundle['confirm']}" action="confirmAttentionTime" oncomplete="handleAttentionTimeServerResponse(xhr, status, args)"
					rendered="#{attentionTimeModel.editedEntity.attentionTimeStatus == 'NEW'}" />
			</p:dialog>
			<script type="text/javascript">
		        function handleAttentionTimeServerResponse(xhr, status, args) {
		            if (!args.validationFailed) {
		            	eventDialog.hide();
		            }
		        }
		    </script>
		</h:form>

	</ui:define>


</ui:composition>